package cn.edu.scnu.movies.service.impl;

import cn.edu.scnu.movies.entity.movies;
import cn.edu.scnu.movies.mapper.IndexMapper;
import cn.edu.scnu.movies.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private IndexMapper indexMapper;

    /**
     * 根据演员姓名查询其主演的电影
     */
    @Override
    public List<movies> actor(String name) {
        // 1. 查询所有匹配的演员ID
        List<Integer> actorIds = indexMapper.findActorIdsByName(name);

        if(actorIds == null || actorIds.isEmpty()){
            return List.of(); // 返回空列表
        }

        // 2. 根据演员ID查询对应的电影
        return indexMapper.findMoviesByActorIds(actorIds);
    }

    /**
     * 根据导演姓名查询其执导的电影
     */
    @Override
    public List<movies> findMoviesByDirector(String name) {
        //根据导演姓名查询该导演指导的电影
        return indexMapper.findMoviesByDirectorName(name);
    }
}
